// 引入axios模块
const axios = require('axios');
const fs = require('fs');

const writer = fs.createWriteStream('output.txt');

// 发起GET请求到/stream路由
axios({
  method: 'GET',
  url: 'http://localhost:3000/stream',
  responseType: 'stream' // 声明响应类型为流
})
.then(response => {
   // 设置流的编码为UTF-8
   response.data.setEncoding('utf8');
  response.data.on('data', (chunk) => {
    // 处理流数据的逻辑
    console.log(chunk);
  });

  response.data.on('end', () => {
    // 数据接收完成的逻辑
    console.log("结束");
  });
  // 通过data事件获取响应流
  // response.data.pipe(writer);
});